<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
import Edit from "./../edit/index";
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
  components: {},
  data() {
    return {
      appWindow: window,
      form: {
        // 是否开启抽奖，0：关闭，1开启
        cost_switch: 0,
        // 扣除积分
        cost: null
      },

      load: true,
    };
  },
  methods: {
    edit(type) {
      Edit.init({
        type: type,
        onSuccess:(res) => {
          console.log(res);
          this.form.cost = res[0]
          console.log(this.form.cost);
        }
      })
    },

    async getData() {
      let res = await this.$vFN.Http.post(
        {
          url: "admin/set/getBase",
        },
        window
      );
      console.log(res.data.cost);
      if(res.data.cost != undefined || res.data.cost != null) {
        this.form = res.data;
      }
      if (res.code == 200) {
        this.load = false;
      }

    },

    async sum() {
      if(this.form.cost_switch == 1 && this.form.cost == null) {
        console.log(1111111111);
        this.$vFN.Tools.messageError("选择要扣除的资产");
        return
      }
      // if(this.cost_switch == 0) {
      //   this.form.cost = null;
      // }
      this.load = true;
      let res = await this.$vFN.Http.post(
        {
          url: "admin/set/setBase",
          data: this.form,
        },
        window
      );
      if (res.code == 200) {
        this.getData()
        this.$vFN.Tools.messageSuccess("设置成功");
      }
    },

    // 初始化
    async init() {
      this.getData();
    },
  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>